package com.example.algorithm.linearsearch;

import com.example.algorithm.entity.Student;
import com.example.algorithm.util.ArrayGenerator;

public class Main {

    public static void main(String[] args) {
//        test1();
        int[] dataSize = {1000000, 10000000};
        for (int n : dataSize) {
            Integer[] data = ArrayGenerator.generateOrderedArray(n);
            long startTime = System.nanoTime();
            for (int k = 0; k < 100; k++) {
                LinearSearch.search(data, n);
            }
            long endTime = System.nanoTime();
            double time = (endTime - startTime) / 1000000000.0;
            System.out.println("n=" + n + ", 100 runs: " + time + " s");
        }
    }

    private static void test1() {
        Integer[] data = {24, 18, 12, 9, 16, 66, 32, 4};
        int res = LinearSearch.search(data, 16);
        assert res == 4;

        res = LinearSearch.search(data, 666);
        assert res == -1;

        Student[] students = {new Student("Alice"),
                new Student("Bobo"),
                new Student("Charles")};
        Student bobo = new Student("Bobo");
        int search = LinearSearch.search(students, bobo);
        System.out.println(search);
    }

}
